package com.wj.exception;

import com.wj.pojo.RespBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * 全局控制层异常处理
 *
 * @author wj
 * @since 1.0.0
 */
@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(SQLException.class)
    public RespBean sqlException(SQLException sqlException){
        if (sqlException instanceof SQLIntegrityConstraintViolationException){
            return RespBean.error("有关联的数据，操作失败");
        }
        return RespBean.error("数据操作异常，操作失败");
    }
}
